package com.cet.algorithm.双指针法.移除元素;

/**
 * @program: algorithm
 * @description: 移除元素
 * @author: 陈恩涛
 * @create: 2022-03-22 15:20
 **/
public class LC27 {

    public int removeElement(int[] nums, int val) {
        int slowIndex = 0;
        for (int fastIndex = 0; fastIndex < nums.length; fastIndex++) {
            if (nums[fastIndex] != val) {
                nums[slowIndex] = nums[fastIndex];
                slowIndex++;
            }
        }
        return slowIndex;
    }

    public static void main(String[] args) {
        LC27 lc27 = new LC27();

        int[] nums = {1, 2, 3, 1};
        System.out.println(lc27.removeElement(nums, 1));
    }
}
